package com.atwork.controller;

import com.atwork.model.normal.SysResource;
import com.atwork.service.SysResourceService;
import com.atwork.utils.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Set;

/**
 * @CreateBy: zhaojun
 * @CreateTime: 2018-08-04
 * @Desc: 资源管理Controller
 */
@Controller
@RequestMapping("/resource")
public class SysResourceController extends BaseController{

    @Autowired
    private SysResourceService sysResourceService;
    /**
     * 获取菜单树
     */
    @ResponseBody
    @RequestMapping(value = "/getResourceTree")
    public Object getResourceTree(){
        Set<SysResource> sysResources = getShiroUser().getSysResource();
        if(sysResources != null && sysResources.size() > 0){
            return ServerResponse.createBySuccess(sysResources);
        }
        return ServerResponse.createByErrorMessage("未获取到任何权限，请联系管理员");
    }
    /**
     * 获取全部菜单
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getAllResource/{pageNum}/{pageSize}")
    public Object getAllResource(@PathVariable("pageNum") int pageNum,
                             @PathVariable("pageSize")int pageSize){

        return sysResourceService.getAllResource(pageNum,pageSize);
    }

    /**
     * 通过id获取菜单
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getResourceById/{id}",
            produces = "application/json;charset=utf-8")
    public Object getResourceById(@PathVariable("id") int id){
        return sysResourceService.getResourceById(id);
    }
}
